import { Injectable } from '@angular/core';
import { RestService } from '@abp/ng.core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

// 通用的下拉框选项数据结构
export interface SelectItem<T = string | number> {
  id: T;
  name: string;
}

@Injectable({
  providedIn: 'root',
})
export class LookupService {
  apiName = 'app';

  constructor(private restService: RestService) {}

  // 货主接口不存在，暂时注释掉
  // getShippers(): Observable<SelectItem[]> {
  //   return this.restService.request<null, { items: any[] }>({
  //     method: 'GET',
  //     url: '/api/app/shippers' // 示例：请替换为实际的货主 API
  //   }).pipe(map(response => response.items.map(item => ({ id: item.id, name: item.name }))));
  // }

  getWarehouses(): Observable<SelectItem<number>[]> {
    return this.restService.request<null, { items: SelectItem<number>[] }>({
      method: 'GET',
      url: '/api/app/customergoods/warehouse-model'
    }).pipe(map(response => response.items));
  }

  getReservedWarehouseAreas(): Observable<SelectItem<number>[]> {
    return this.restService.request<null, { items: SelectItem<number>[] }>({
      method: 'GET',
      url: '/api/app/customergoods/reserved-warehouse-area-model'
    }).pipe(map(response => response.items));
  }

  getOrderTypes(): Observable<SelectItem<number>[]> {
    return this.restService.request<null, { items: SelectItem<number>[] }>({
      method: 'GET',
      url: '/api/app/customergoods/order-type-model'
    }).pipe(map(response => response.items));
  }
} 